home *** CD-ROM | disk | FTP | other *** search
/ Internet.Works 39 / Issue 39.iso / pc / PCSoftware / Visual Perl Editor / visualperl.exe / {app} / counter.cgi < prev    next >
Encoding:
Text File  |  2000-09-27  |  821 b   |  45 lines

  1. #!C:\Perl\bin\perl.exe
  2.  
  3. #@Local#?#@Server
  4.  
  5. ### Using the command converter, 4 changes are made here when
  6. ### you press toggle, at lines 1,2,15,17,21
  7. ### Note, for changes in line 1 and 21 to occur, you must have the original
  8. ### change templates in the command converter with the setup of VPE.
  9.  
  10. use strict;
  11. use Fcntl qw(:flock);
  12.  
  13. print "Content-Type: text/html\n\n";
  14.  
  15. my $semaphore_file=
  16.  'counter.sem';#?'/tmp/counter.sem';
  17. my $counter_file=
  18.  'counter.log';#?'/docs/logs/counter.log';
  19.  
  20. sub get_lock {
  21.  open(SEM,">$semaphore_file");
  22.  #flock(SEM,LOCK_EX);
  23. }
  24.  
  25. sub release_lock {
  26.  close(SEM)
  27. }
  28.  
  29. get_lock();
  30. my $hits = 0;
  31. if (open(CF,$counter_file)) {
  32.  $hits=<CF>;
  33.  close(CF);
  34. }
  35.  
  36. $hits++;
  37. print "$hits<br>";
  38.  
  39. open(CF,">$counter_file");
  40. print CF $hits;
  41. close(CF);
  42.  
  43. release_lock();
  44.  
  45.